package cn.jly.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * @author lanyangji
 * @description
 * @date 2020/12/17 下午 1:57
 */
public class JsoupTest {
    public static void main(String[] args) throws IOException {
//        final Document document = Jsoup.parse(
//                new URL("https://www.cnblogs.com/zhangyinhua/p/8037599.html"),
//                60 * 1000
//        );

        final Document document = Jsoup.connect("https://www.cnblogs.com/zhangyinhua/p/8037599.html").get();
        final String title = document.title();
        System.out.println("title = " + title);

        // 爬取网站所有的超链接
        final Elements links = document.getElementsByTag("a");
        for (Element link : links) {
            System.out.println(link.attr("href") + " -> " + link.text());
        }
    }
}
